package com.partner.springsecurity;

import java.io.IOException;  
import java.text.SimpleDateFormat;  
import java.util.Date;  
  


import javax.servlet.ServletException;  
import javax.servlet.http.HttpServletRequest;  
import javax.servlet.http.HttpServletResponse;    

import org.springframework.beans.factory.annotation.Autowired;  
import org.springframework.security.core.Authentication;  
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;  

import com.partner.bean.sysright.TLoginlog;
import com.partner.frame.common.ConstantsMark;
import com.partner.service.sysright.SysLoginlogManagerService;
  
public class CustomLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {  
      
	@Autowired
	private SysLoginlogManagerService sysLoginlogManagerService;
	
    @Override  
    public void onLogoutSuccess(HttpServletRequest request,  
            HttpServletResponse response, Authentication authentication)  
            throws IOException, ServletException {  
        //System.out.println("用户退出成功处理。。。。");   
    	
        String userName = authentication.getName(); //用户名  
        String address =  request.getRemoteAddr();  //远程地址  
         
        //新增用户退出日志
        TLoginlog log = new TLoginlog();
        log.setContent(ConstantsMark.LOGINLOG_OUT);
        log.setTime(new Date(System.currentTimeMillis()));
        log.setIp(address);
        log.setUsername(userName);
        sysLoginlogManagerService.insert(log);
        super.onLogoutSuccess(request, response, authentication);  
      
          
    }  
  
  
  
} 
